package com.supermap.dataservice.project.mapper;

import com.supermap.dubbo.api.product.entity.ExpertProduct;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

/**
 * @version v1.0.0
 * @Author:zhoujian
 * @Desciption:
 * @date 2019-07-03 11:42
 */
@Mapper
public interface ExpertProductMapper {


    /**
     * 添加专家经验性产品
     * @param expertProduct
     * @return
     */
    @Insert("insert into t_expert_product(expid , title , content ," +
            " areacode , town_code , product_type ,crops_type, crops_id , " +
            "crops_puberty_id , knowledge , createtime) \n" +
            "values(#{expertId},#{title},#{content},#{areaCode},#{townCode},#{productType},#{cropsType},#{cropsId},#{cropsPubertyId},#{knowledge},#{createTime,jdbcType=TIMESTAMP})")
    @Options(useGeneratedKeys=true, keyProperty="productId", keyColumn="product_id")
    public int insertExpertProduct(ExpertProduct expertProduct);

    /**
     * 根据产品类型(作物大类，作物小类，作物生育期 选填)查询产品列表
     * @param productType
     * @param cropType
     * @param cropsId
     * @param cropsPubertyId
     * @return
     */
    @Select("<script>" +
            "SELECT t.product_id AS productId, t.expid AS expertId, \n" +
            "t.title, t.content, t.areacode as areaCode, t.town_code AS townCode, \n" +
            "t.product_type AS productType, t.crops_type as cropsType ,\n" +
            "t.crops_id as cropsId, t.crops_puberty_id as cropsPubertyId, \n" +
            "t.knowledge, date_format(t.createtime,'%Y-%m-%d %H:%i:%S') as createTime\n" +
            "FROM t_expert_product t " +
            "where " +
            "t.knowledge = 1 " +
            "AND t.status = 1 " +
            "<if test='productType != null '> " +
            " and t.product_type = #{productType}" +
            "</if>" +
            "<if test = 'cropType != null'>" +
            "and t.crops_type = #{cropType}" +
            "</if>" +
            "<if test = 'cropId != null'>" +
            "and t.crops_id = #{cropId}" +
            "</if>" +
            "<if test = 'cropsPubertyId != null'>" +
            "and t.crops_puberty_id = #{cropsPubertyId}" +
            "</if>" +
            "ORDER BY t.createtime DESC" +
            "</script>")
    public List<Map<String,Object>> queryByCropAndTypeList(@Param("productType") Integer productType, @Param("cropType") String cropType, @Param("cropId") String cropsId, @Param("cropsPubertyId") Integer cropsPubertyId);


}